package shu;

import java.util.Scanner;

public class test {

    public static void main(String[] args) {
//		SeqBT s = new SeqBT(10);
//		s.CreatBT();
//		s.print();
//        makeTree();
//        System.out.print("DLR:");
//        BiTreeNode mytree = makeTree();
//        Traverse.preOrder(mytree);
//        System.out.println();
//
//        System.out.print("LDR:");
//        Traverse.inOrder(mytree);
//        System.out.println();
//
//        System.out.print("LRD:");
//        Traverse.outOrder(mytree);
//        System.out.println();

        BiTreeNode mytree = create(null);
        Traverse.preOrder(mytree);
        System.out.println(height(mytree));
    }
    private static BiTreeNode makeTree() {
        BiTreeNode a,b,c,d,e,f;
        e = new BiTreeNode('e',null,null);//叶子
        f = new BiTreeNode('f',null,null);
        d = new BiTreeNode('d',f,null);
        c = new BiTreeNode('c',null,d);
        b = new BiTreeNode('b',null,e);
        return new BiTreeNode("a",b,c);//返回根
    }
    //先序创建二叉树
    public static BiTreeNode create(BiTreeNode bt){
        Scanner sc = new Scanner(System.in);
        System.out.print("节点的值：");
        char ch = sc.next().charAt(0);
        if(ch=='#'){
            bt=null;//建立空二叉树
        }else{
            bt = new BiTreeNode();
            bt.data=ch;
            bt.lchild=create(bt.lchild);//先序创建左子树
            bt.rchild=create(bt.rchild);//先序创建左子树
        }
        return bt;
    }
    //计算机二叉树总数
    public static int nodcount(BiTreeNode bt){
        if(bt==null){
           return 0;
        }else{
           return nodcount(bt.rchild)+nodcount(bt.lchild)+1;
        }
    }

    //计算机二叉树叶子节点总数
    public static int leafcount(BiTreeNode bt){
        if(bt==null){
            return 0;
        } else if (bt.rchild==null && bt.lchild==null) {//该节点为叶子
            return 1;
        } else{
            return leafcount(bt.rchild)+leafcount(bt.lchild);//不是叶子树就左子树+右子树
        }
    }
//计算机二叉树深度
    public static int height(BiTreeNode bt){
        if(bt==null){
            return 0;
        }else{
            return Math.max(height(bt.rchild),height((bt.lchild)))+1;
        }
    }

}
